// comment-list.jsx
import React, { useEffect, useState } from 'react';
import req from '@utils/request';
import { message } from 'antd';
import CommentItem from './comment-item'; // 假设 CommentItem 组件在同一目录下

const CommentList = ({ circleId ,deleteComment}) => {
    const [commenList, setCommenList] = useState([]);

    const get_comment_list = () => {
        if (!circleId) return;
        req(
            {
                method: 'post',
                url: '/share/comment/list',
                data: { id: circleId }
            }, "/circle"
        ).then(res => {
            setCommenList(res.data);
        }).catch(err => {
            // 提取错误信息并显示
            const errorMessage = err.message || err.toString() || JSON.stringify(err);
            message.error(errorMessage);
        });
    };

    useEffect(() => {
        get_comment_list();
    }, [circleId]);

    const commentIsUpdate = (montentId) => {
        get_comment_list();
        deleteComment(montentId)
        console.log('commentIsUpdate');
    };

    return (
        <div>
            {commenList.map((item, index) => (
                <CommentItem key={index} comment={item} onCommentdelet={commentIsUpdate} />
            ))}
        </div>
    );
};

export default CommentList;